import java.util.Hashtable;

/*
 * This class (data structure) would store the usage data regarding the power usage from the 
 * beginning of the program.
 * 
 * 	It would store the following information :	
 * 		
 * 		1. The average power consumed by each of the resource/cluster.
 * 		2. Resource capability - The amount of extra load it can take without significant 
 * 								 increase in power consumption.
 */

public class ServerClusterUsageData implements IServerClusterUsageData
{
	private Hashtable<Integer,IServerUsageData> serverUsageTable = null;
	
	public ServerClusterUsageData()
	{
		serverUsageTable = new Hashtable<Integer,IServerUsageData>();
	}
	
	public void addUsageData(int key, Double newPowerConsumption)
	{
		// calculate the power average and the resource capability by the data present and the
		// given data set , and then update the new values into the data structure.
		
		if(!serverUsageTable.containsKey(new Integer(key)))
		{
			// create a new RUD and do the necessary calculations.
			// add the given key along with the created RUD into the hashtable. 
			
			IServerUsageData resourceData = new ServerUsageData(newPowerConsumption,1.0);
			serverUsageTable.put(new Integer(key), resourceData);
		}
		
		else
		{
			// extract the particular RUD
			// perform the calculations required
			// updated the RUD
			
			serverUsageTable.get(new Integer(key)).adjustPowerAverage(newPowerConsumption);			
		}
	}
	
	public Double getServerAverage(int key)
	{
		if(serverUsageTable.containsKey(new Integer(key)))
			return serverUsageTable.get(new Integer(key)).getPowerAverage().doubleValue();
		else
			return -100.0;
	}
	
	public Double getServerCapability(int key)
	{
		if(serverUsageTable.containsKey(new Integer(key)))
			return serverUsageTable.get(new Integer(key)).getServerCapability().doubleValue();
		else
			return -100.0;
	}
}
